<%--
  Created by IntelliJ IDEA.
  User: sxs
  Date: 2020/8/13
  Time: 15:34
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">

    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="description" content="">
    <meta name="author" content="">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" href="${AppPath}/css/font.css">
    <link rel="stylesheet" href="${AppPath}/css/index.css">
    <link rel="stylesheet" href="${AppPath}/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="${AppPath}/ztree/font-awesome.min.css">
    <link rel="stylesheet" href="${AppPath}/ztree/main.css">
    <link rel="stylesheet" href="${AppPath}/layer/skin/default/layer.css">
    <link rel="stylesheet" href="${AppPath}/ztree/zTreeStyle.css">
    <style>
        .tree li {
            list-style-type: none;
            cursor:pointer;
            font-size: x-large;
        }

        table tbody tr:nth-child(odd){background:#F4F4F4;}
        table tbody td:nth-child(even){color: #cc0000;}
    </style>
</head>

<body >
<!-- <div class="x-slide_left"></div> -->
<!-- 左侧菜单结束 -->
<!-- 右侧主体开始 -->
<div class="col-sm-12 col-md-12  main">

    <div class="panel panel-default">
        <input type="hidden" id="roleId" name="roleId" value="${roleId}">
        <div class="panel-heading"><i class="glyphicon glyphicon-th-list"></i> 权限分配 <div style="float:right;cursor:pointer;" data-toggle="modal" data-target="#myModal"><i class="glyphicon glyphicon-question-sign"></i></div></div>
        <div class="panel-body">
            <ul id="treeDemo" class="ztree"></ul>
        </div>
        <div class="layui-card-header">
            <button class="layui-btn layui-btn-danger layui-btn-sm" id="addpower"><i class="layui-icon"></i>确认</button>
        </div>
    </div>
</div>
</div>
</div>
<script src="${AppPath}/lib/layui/layui.js" charset="utf-8"></script>
<script type="text/javascript" src="${AppPath}/js/index.js"></script>
<script type="text/javascript" src="${AppPath}/jquery/jquery-2.1.1.min.js"></script>
<script src="${AppPath}/bootstrap/js/bootstrap.min.js"></script>
<script src="${AppPath}/script/docs.min.js"></script>
<script src="${AppPath}/layer/layer.js"></script>
<script src="${AppPath}/ztree/jquery.ztree.all-3.5.min.js"></script>
<script type="text/javascript">

    var setting = {
        view: {
            selectedMulti: false,

            fontCss: {
                color: "blue",
            },

        },
        async: {
            enable: true,
            url:"${AppPath}/role/rolePowerAjax?roleId="+${roleId},
        },

        check: {
            enable: true,
            autoCheckTrigger: true,
        },

        data: {
            simpleData: {
                enable: true,
            },
            key:{
                checked:"checked",
                name:"powerNmae",
                id:"powerId",
                pId:"parentId",
            }
        },
    }

    $(function () {
        $.fn.zTree.init($("#treeDemo"),setting);
        $("#addpower").click(function () {
            var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
            var nodes = treeObj.getCheckedNodes(true);
            var roleId=[];
            var roles=$("#roleId").val();
           for(var  i=0;i<nodes.length;i++){
              roleId[i]=nodes[i].powerId;
           };
           $.ajax({
               url:"${AppPath}/role/rolePowerAdd",
               type:"post",
               data:{"rp":roleId,"roleId":roles},
               traditional:true,
               success:function (data) {
                    if(data.result=="ok"){
                        layer.msg("增加成功!",{time:1000,icon:6},function () {
                        });


                    }else{
                        layer.msg("增加失败", {time:1000, icon:2, shift:6},function () {});
                    }

               }
           })
        })

    });


</script>
</body>
</html>

